<template>
	<view>
		<uni-indexed-list :options="list" :showSelect="true" @click="bindClick"></uni-indexed-list>
		<view class="determine flex" @click="determineFn()">
			确定
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				
				userInfo: uni.getStorageSync("userInfo"),
				list: [{
					// "letter": "A",
					"data": []
				}],
				idString: ''
			}
		},
		onLoad() {

			this.init()



		},
		methods: {
			async init() {


				const res = await this.$http.post({
					url: this.$api.myFansUser,
					data: {
						page: 1,
						limit: 50

					},
					headers: {
						'Authorization': this.userInfo.token
					}

				})

				if (res.code == 0) {

					this.list[0].data = res.data.list.map((item) => {
						return {
							name: item.nickname,
							value: item.id,
							avatar: item.avatar,

						}
					})
					
					if (uni.getStorageSync("idString").length) {
						const idList = uni.getStorageSync("idString").map((item) => {
							return item.id

						})
						// console.log(idList)
						this.list[0].data.forEach(item => {
						    // 检查当前对象的 id 是否在 idsToMatch 数组中
						    if (idList.includes(item.value)) {
						        // 如果匹配到，添加 check: true 属性
						        item.checked = true;
						    }
						});
						console.log(this.list[0].data)
					}

				} else {

					this.$sun.toast(res.msg, 'none')
				}

			},
			bindClick(e) {
				// 处理点击事件

				this.idString = e.select.map((item) => {
					return {
						id: item.vlaue,
						nickname: item.name,
						avatar: item.avatar,
						checked: item.checked
					}
				})

				// 可以在这里编写具体的处理逻辑，比如跳转到详情页等
			},
			determineFn() {

				// this.idString= this.idString.join(','); 
				uni.setStorageSync('idString', this.idString)
				this.$sun.navBack()
			}
		}
	}
</script>
<style lang="less" scoped>
	.determine {
		z-index: 99;
		width: 95%;
		height: 102rpx;
		border-radius: 142rpx;
		color: #fff;
		position: fixed;
		margin-left: 17rpx;
		bottom: 20rpx;
		background: rgb(120, 93, 246);
	}
</style>